package org.platform.lwc.system.controller;

import org.platform.lwc.system.mongodb.document.MemberReadHistory;
import org.platform.lwc.system.service.MemberReadHistoryService;
import org.platform.lwc.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * mongodb 操作 demo
 *
 * @author lwc
 * @since 2022-04-09
 */
@RestController
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {
    @Autowired
    private MemberReadHistoryService memberReadHistoryService;

    /**
     * description:创建浏览记录
     */
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public R create(@RequestBody MemberReadHistory memberReadHistory) {
        int count = memberReadHistoryService.create(memberReadHistory);
        if (count > 0) {
            return R.data("ok");
        } else {
            return R.fail("创建失败!");
        }
    }

    /**
     * description:删除浏览记录
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public R delete(@RequestParam("ids") List<String> ids) {
        int count = memberReadHistoryService.delete(ids);
        if (count > 0) {
            return R.data("ok");
        } else {
            return R.fail("创建失败!");
        }
    }

    /**
     * description:展示浏览记录
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R<List<MemberReadHistory>> list(Long memberId) {
        List<MemberReadHistory> memberReadHistoryList = memberReadHistoryService.list(memberId);
        return R.data(memberReadHistoryList);
    }

}
